package com.atguigu.gmall.seckill.rpc;/*
 * @author: XueYouPeng
 * @time: 23.8.2 下午 8:49
 */

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.order.entity.OrderInfo;
import com.atguigu.gmall.seckill.entity.SeckillGoods;
import com.atguigu.gmall.seckill.service.SeckillGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/api/inner/seckill")
public class SeckillRpcController {

    @Autowired
    private SeckillGoodsService seckillGoodsService;

    @GetMapping(value = "/findAll")
    public Result<List<SeckillGoods>> findAll(){
        List<SeckillGoods> seckillGoodsList = seckillGoodsService.findAll();
        return Result.build(seckillGoodsList , ResultCodeEnum.SUCCESS);
    }

    @GetMapping(value = "/item/{skuId}")
    public Result<SeckillGoods> findBySkuId(@PathVariable(value = "skuId") Long skuId){
        SeckillGoods seckillGoods = seckillGoodsService.findBySkuId(skuId);
        return Result.build(seckillGoods , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping(value = "/findOrderInfoBySkuId/{skuId}")
    public Result<OrderInfo> findOrderInfoBySkuId(@PathVariable(value = "skuId") Long skuId){
        OrderInfo orderInfo = seckillGoodsService.findOrderInfoBySkuId(skuId);
        return Result.build(orderInfo , ResultCodeEnum.SUCCESS) ;
    }
}
